package com.a16.yuejian.yuejian.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.a16.yuejian.yuejian.R;
import com.a16.yuejian.yuejian.activity.ClubVideoActivity;
import com.a16.yuejian.yuejian.javabean.Video;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 王子恒 on 2017/11/8.
 */

public class ClubVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubVideoAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.clubvideo_cardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Video entity = (Video) mDataList.get(position);
        if (null == entity){
            return;
        }else {
            final ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.clubvideo_name.setText(entity.getVideoname());
            Picasso.with(mContext).load("http://10.0.2.2:8080/neu_yuejian201/public/photo/"+entity.getPic()).into(viewHolder.club_videoimg);
            viewHolder.club_videocontainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, ClubVideoActivity.class);
                    mContext.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {return mDataList.size();}

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView clubvideo_name;
        LinearLayout club_videocontainer;
        ImageView club_videoimg;

        public ViewHolder(View itemView) {
            super(itemView);
            clubvideo_name = (TextView) itemView.findViewById(R.id.clubvideo_name);
            club_videoimg = (ImageView) itemView.findViewById(R.id.club_video_img);
            club_videocontainer= (LinearLayout)itemView.findViewById(R.id.club_videocontainer);
        }
    }
}
